package com.xjy.web.controller.controller;

import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.enums.BusinessType;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.system.domain.bo.ReportProjBudgetQueryBo;
import com.xjy.system.domain.vo.ReportProjBudgetVo;
import com.xjy.system.service.IReportProjBudgetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 预算执行情况Controller
 *
 * @author mlb
 * @date 2022-03-17
 */
@Api(value = "预算执行情况控制器", tags = {"预算执行情况管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/report_proj_budget")
public class ReportProjBudgetController extends BaseController {

	private final IReportProjBudgetService iReportProjBudgetService;

	/**
	 * 查询预算执行情况列表
	 */
	@ApiOperation("查询预算执行情况列表")
	@PreAuthorize("@ss.hasPermi('system:report_proj_budget:list')")
	@GetMapping("/list")
	public TableDataInfo<ReportProjBudgetVo> list(@Validated ReportProjBudgetQueryBo bo) {
		return iReportProjBudgetService.queryPageList(bo);
	}

	/**
	 * 导出预算执行情况列表
	 */
	@ApiOperation("导出预算执行情况列表")
	@PreAuthorize("@ss.hasPermi('system:report_proj_budget:export')")
	@Log(title = "预算执行情况", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<ReportProjBudgetVo> export(@Validated ReportProjBudgetQueryBo bo) {
		List<ReportProjBudgetVo> list = iReportProjBudgetService.queryList(bo);
		ExcelUtil<ReportProjBudgetVo> util = new ExcelUtil<ReportProjBudgetVo>(ReportProjBudgetVo.class);
		return util.exportExcel(list, "预算执行情况");
	}

	/**
	 * 获取预算执行情况详细信息
	 */
	@ApiOperation("获取预算执行情况详细信息")
	@PreAuthorize("@ss.hasPermi('system:report_proj_budget:query')")
	@GetMapping("/{projId}")
	public AjaxResult<ReportProjBudgetVo> getInfo(@NotNull(message = "主键不能为空")
												  @PathVariable("projId") Long projId) {
		return AjaxResult.success(iReportProjBudgetService.queryById(projId));
	}


}
